<?php 
global $wpdb;

$s = $_GET["s"] !== null ? $_GET["s"] : "";
$m = $_GET["m"] !== null ? $_GET["m"] : "";
$id = '';

$link_payment = HFR_SERVER."/rest/payment?c=".get_option("hfr_customer")."&k=".get_option("hfr_license_key")."&r=".urlencode(get_option('hfr_blog_url'))."/wp-admin/admin.php?page=hfr_payment";
?>

<div class="hfr-body">
	<h2 class="title">Payment</h2>
<?php 
if ($s == "0" && $m != "") {
?>
<div class="hfr-alert-danger"><?=$m?></div>
<?php 
} else if ($s == "1") {
	
	$rs = $_GET['rs'] != null ? urldecode($_GET['rs'])  : "";
	$rs = preg_replace('/[\\\]/i', "", $rs);
	$payment = json_decode($rs);
	
	if (isset($payment->id) && $payment->id != "") {
		$sql = "SELECT * FROM ".$wpdb->prefix."hfr_payment WHERE id = '".$payment->id."'";
		$row = $wpdb->get_row($sql);
		if ($row === NULL ) {
			$wpdb->query( $wpdb->prepare(
					"
					INSERT INTO ".$wpdb->prefix."hfr_payment
					( 
						`id`, `customer`, `price`, `content`, `created`, `start`, `end`
					)
					VALUES ( %s, %s, %d, %s, %s, %s, %s)
					",
					$payment->id, $payment->customer, $payment->price, $payment->note, $payment->created, $payment->start, $payment->end
			) );
		}
		$id = $payment->id;
?>
<div class="hfr-alert-success">Thanks for your payment. Your transaction Id is <?=$payment->id ?></div>		
<?php 
	}
} 

$sql = "SELECT * FROM ".$wpdb->prefix."hfr_payment ORDER BY end DESC";
$rows = $wpdb->get_results($sql);
?>
    
    
    <div class="hfr-transaction">
    	<table class="hfr-table">
        	<thead>
            	<tr>
                	<th>Buyer</th>
                    <th>Price</th>
                    <th>Transaction ID</th>
                    <th>Date Purchased</th>
                    <th>Date Start</th>
                    <th>Date Expired</th>
                </tr>
            </thead>
            <tbody>
<?php        
			for($i=0; $i < count( $rows ); $i++) {
				$row = $rows[$i];
?>
            	<tr class="<?=($id == $row->id) ? "active" : "" ?>">
                	<td><?=$row->customer ?></td>
                    <td>$<?=$row->price ?></td>
                    <td><?=$row->id?></td>
                    <td><?=$row->created ?></td>
                    <td><?=$row->start ?></td>
                    <td><?=$row->end ?></td>
                </tr>
<?php
			} 
?>
            </tbody>
            <tfoot>
            	<tr>
                	<th colspan="5">If you have any questions or need our assistance, please <a href="#">contact with us</a>.</th>
                </tr>
            </tfoot>
        </table>
    </div>
    
	<div class="hfr-payment clearafter">
        <ul>
            <li><a href="<?=$link_payment?>" class="hfr-btn-blue">Buy License - $20 / year</a></li>
            <li>Your content will be updated daily</li>
            <li>All images are hosted at google's cdn</li>
            <li>Easy earning money from your site even you are sleeping. </li>
            <li>Create many different types of sites</li>
            <li>Save your time & money</li>
            <li><a href="#">And more ...</a></li>
            <li><strong>If you have any questions, please <a href="#">contact with us</a>.</strong></li>
        </ul>
    </div>

</div>